const getSearchObj = () => {
  // ?a=1&b=2
  const { search } = window.location;

  // a=1&b=2
  const searchStr = search.slice(1);

  // [a=1, b=2]
  const searchArr = searchStr.split("&");

  // {a:1, b:2}
  const searchObj = searchArr.reduce((prev, next) => {
    const [key, value] = next.split("=");
    prev[key] = value; // eslint-disable-line no-param-reassign
    return prev;
  }, {} as { [key: string]: string });

  return searchObj;
};

export default getSearchObj;
